import type { StepTaskModel } from './models';

import { requestClient } from '#/api/request';

/**
 * 获取工步数据集合
 * @param stepId 工艺步骤 Id
 * @returns 返回查询结果
 */
export async function getStepTaskListApi(stepId: number) {
  return requestClient.get<StepTaskModel[]>('/mes/process/stepTask/list', {
    params: { stepId },
  });
}

/**
 * 创建工步
 * @param data 要创建的工步数据
 * @returns 返回结果
 */
export async function createStepTaskApi(data: any) {
  return requestClient.post<boolean>('/mes/process/stepTask', data);
}

/**
 * 复制工步
 * @param data 要创建的工步数据
 * @returns 返回结果
 */
export async function copyStepTaskApi(data: {
  count: number;
  stepTaskId: number;
  taskCodePrefix: string;
  taskNamePrefix: string;
}) {
  return requestClient.post<boolean>('/mes/process/stepTask/copy', data);
}

/**
 * 更新工步
 * @param id 工步 Id
 * @param data 要更新的工步
 * @returns 返回结果
 */
export async function updateStepTaskApi(id: number, data: any) {
  return requestClient.put<boolean>(`/mes/process/stepTask/${id}`, data);
}

/**
 * 重组工步顺序号，顺序号从分组区间中按顺序重新排列
 * @param stepId 工艺步骤 Id
 * @returns 返回结果
 */
export async function reorganizeStepTaskSeqAsyncApi(stepId: number) {
  return requestClient.put<boolean>(
    `/mes/process/stepTask/reorganize/${stepId}`,
  );
}

/**
 * 删除工步
 * @param id 工步 Id
 * @returns 返回结果
 */
export async function deleteStepTaskApi(id: number) {
  return requestClient.delete<boolean>(`/mes/process/stepTask/${id}`);
}
